#pragma once

#include <iostream>
#include <string>

#define Die(code)   \
    do              \
    {               \
        exit(code); \
    } while (0)

#define CONV(v) (struct sockaddr *)(v)

enum 
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR
};

const int gdefaultsock = -1;
const int gbacklog = -1;

bool ParseOneLine(std::string& str, std::string* out, 
    const std::string& sep)
{
    auto pos = str.find(sep);
    if (pos == std::string::npos) return false;
    *out = str.substr(0, pos);
    str.erase(0, pos + sep.size());
    return true;
}